package com.yang.myoschina.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.yang.myoschina.R;
import com.yang.myoschina.bean.News;

import java.util.List;

/**
 * Created by yangjianquan on 2016/11/4.
 */

public class NewsAdapter extends ArrayAdapter<News>{

    public NewsAdapter(Context context, int resource, List<News> objects) {
        super(context, resource, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        Viewholder viewHolder;
        if (null==convertView){
            viewHolder = new Viewholder();
            view = LayoutInflater.from(getContext()).inflate(R.layout.news_listview,null);
            viewHolder.title = (TextView)view.findViewById(R.id.newTitle);
            viewHolder.content = (TextView)view.findViewById(R.id.newsContent);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (Viewholder)convertView.getTag();
        }
        News news = getItem(position);
        viewHolder.title.setText(news.getTitle());
        viewHolder.content.setText(news.getBody());
        return view;
    }

    static class Viewholder {
        private TextView title;
        private TextView content;
    }
}
